package week4;
import java.util.Scanner;
/**
 * Created by dell on 2017/3/14.
 */
public class CancellationError {
    public static void main(String[] args){
        int n;
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入n的值：" );
        n = scanner.nextInt();
        Right(n);
        Left(n);
    }
    public static void Right(int n){
        float sum = (float) 0;
        int i;
        for(i = 1; i <= n; i++){
            //sum += 1/i;
            sum += (float) 1/i;
        }
        System.out.println("从左向右和为：" + sum);
    }
    public static void Left(int n){
        float sum = (float) 0;
        int i;
        for(i = n ; i >= 1; i --){
            //sum += 1/i;
            sum += (float) 1/i;
        }
        System.out.println("从右向左和为：" + sum);
    }
}
